using System;
using System.IO;
using DesignPatternDefinitions;

namespace CodeGenerators
{
	internal class DefaultComponentGenerator : IDPAComponentGenerator
	{
		#region IDPAComponentGenerator Members
		public string GenerateComponent(string directory, DesignPatternDefinitions.IProjectComponent component)
		{
			string projectRoot = directory + "\\" + component.ComponentName;
			if( ! Directory.Exists( projectRoot ) )
				Directory.CreateDirectory( projectRoot );
			CreateReadmeFile(projectRoot,component);
			return projectRoot;
		}
		#endregion

		#region Implementation Functions
		
		private void CreateReadmeFile(string projectRoot, IProjectComponent component)
		{
			try
			{
				string filename = projectRoot + "\\Readme.txt" ;
				StreamWriter writer = new StreamWriter(filename);
				writer.WriteLine( "Name : {0}" , component.ComponentName );
				writer.WriteLine( "Author : {0}" , component.ComponentAuthor );
				writer.WriteLine( "Summary : {0}" , component.ComponentSummary );
				writer.Close();
			}
			catch
			{
			}
		}
		#endregion
	}
}
